package com.oa.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oa.bean.Notice;
import com.oa.bean.User;
import com.oa.dao.NoticeDao;
import com.oa.service.NoticeService;

@Service
public class NoticeServiceImpl implements NoticeService{

	@Resource
	NoticeDao noticeDao;
	
	@Override
	public Integer addNotice(Notice notice) {
		// TODO Auto-generated method stub
		Integer result = noticeDao.insertNotice(notice);
		return result;
	}

	@Override
	public Map<String,Object> getNoticeList(int currentPage,Integer deptno) {
		// TODO Auto-generated method stub
		Page page=PageHelper.startPage(currentPage, 2,"n.nid desc");
		List<Notice> list = noticeDao.selectNoticeList(deptno);
		Map<String,Object>map = new HashMap<>();
		map.put("noticeList", list);
		
		map.put("total", page.getPages());
		map.put("limt", 2);
		map.put("currentPage", currentPage);
		
		return map;
	}

	@Override
	public String deleteNotice(Integer nid) {
		// TODO Auto-generated method stub
		Integer result = noticeDao.delectNoticeById(nid);
		if(result!=0){
			return "true";
		}
		return "false";
	}

	@Override
	public Notice lookNoticeDetails(Integer nid) {
		// TODO Auto-generated method stub
		System.out.println(nid);
		Notice notice = noticeDao.selectNoticeDetils(nid);
		return notice;
	}
	

}
